#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>

using namespace std;

int ans = 0;
int main_cross[19],vice_cross[19],cols[10];

void backtrack(int i, int N)
{
    if (i == N)
    {
        ++ans;
        return;
    }
    for (int j = 0; j < N; j++)
    {
        if (!main_cross[i + j] && !vice_cross[i - j + N - 1] && !cols[j])
        {
            main_cross[i + j] = vice_cross[i - j + N - 1] = cols[j] = 1;
            backtrack(i+1, N);
            main_cross[i + j] = vice_cross[i - j + N - 1] = cols[j] = 0;
        }
    }
}

int main()
{
    int N;
    int table[10];
    for(int i=0;i<10;i++)
    {
        memset(main_cross,0,sizeof(main_cross));
        memset(vice_cross,0,sizeof(vice_cross));
        memset(cols,0,sizeof(cols));
        ans = 0;
        backtrack(0,i+1);
        table[i] = ans;
    }
    while (scanf("%d", &N))
    {
        if (N == 0)
            break;
        cout << table[N-1] << endl;
    }

    return 0;
}